package com.itheima.nosql;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

@SpringBootApplication
@EnableTransactionManagement
@Configuration
public class App {

    @Value("${spring.redis.nodes}")
    String nodes;

    public static void main(String[] args) {
        new SpringApplicationBuilder(App.class).run(args);
    }

    @Bean
    public JedisCluster getJedisCluster(){
        String[] ns=nodes.split(",");
        Set<HostAndPort> nodes=new HashSet<>();

        for (String node:ns){
            String[] n=node.split(":");
            nodes.add(new HostAndPort(n[0].trim(),Integer.valueOf(n[1].trim())));

        }
        return  new JedisCluster(nodes,60000);
    }


}